package com.zygh.policeasset.controller;

import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.mapper.QueryComponentMapper;
import com.zygh.policeasset.pojo.dto.QueryComponentDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/queryComponent"})
@Api(tags = {"查询组件管理"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/QueryComponentController.class */
public class QueryComponentController {
    @Autowired
    QueryComponentMapper queryComponentMapper;

    @RequestMapping(value = {"/findAll"}, method = {RequestMethod.GET})
    @ApiOperation("查询所有")
    public Object findAll(@RequestParam(value = "classify", required = false) String classify,
                          @RequestParam(value = "componentShow", required = false) Integer componentShow) {
        return this.queryComponentMapper.findAll(classify, componentShow);
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @Transactional
    @ApiOperation("修改组件")
    public Object update(@RequestBody List<QueryComponentDTO> queryComponentDTOList) {
        try {
            for (QueryComponentDTO queryComponentDto : queryComponentDTOList) {
                if (this.queryComponentMapper.update(queryComponentDto.getSort(), queryComponentDto.getComponentShow(), queryComponentDto.getId()).intValue() == 0) {
                    return new CommonResult().validateFailed("修改失败");
                }
            }
            return new CommonResult().success();
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return new CommonResult().validateFailed(e.getCause().getMessage());
        }
    }
}